package Model;

import Util.FormatDate;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;

/**
 *
 * @author Max
 */
@Entity
public class Noticia implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(nullable = false)
    private String titulo;
    @Column(nullable = false)
    private String chamada;
    @Lob
    @Column(nullable = false)
    private String texto;
    @Column (nullable = false)
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date dataHora;
    @ManyToOne
    private UsuarioPetiano autor;

    public Noticia() {
    }

    public UsuarioPetiano getAutor() {
        return autor;
    }

    public void setAutor(UsuarioPetiano autor) {
        this.autor = autor;
    }

    public String getTitulo() {
        return titulo;
    }

    public void setTitulo(String titulo) {
        this.titulo = titulo;
    }

    public String getChamada() {
        return chamada;
    }

    public void setChamada(String chamada) {
        this.chamada = chamada;
    }

    public String getTexto() {
        return texto;
    }

    public void setTexto(String texto) {
        this.texto = texto;
    }

    public Date getDataHora() {
        return dataHora;
    }

    public void setDataHora(Date dataHora) {
        this.dataHora = dataHora;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String printTitulo() {
        if (this.titulo != null) {
            return this.titulo;
        } else {
            return "";
        }
    }

    public String printChamada() {
        if (this.chamada != null) {
            return this.chamada;
        } else {
            return "";
        }
    }

    public String printTexto() {
        if (this.texto != null) {
            return this.texto;
        } else {
            return "";
        }
    }

    public String printDataHora() {
        if (this.dataHora != null) {
            return FormatDate.dateTimeToString(this.dataHora);
        } else {
            return "";
        }
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Noticia)) {
            return false;
        }
        Noticia other = (Noticia) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Model.Noticia[ id=" + id + " ]";
    }
}
